package cn.fldong.service.impl;

import cn.fldong.dao.StudentDAO;
import cn.fldong.dao.impl.StudentDAOImpl;
import cn.fldong.model.Student;
import cn.fldong.service.StudentService;
import java.sql.SQLException;
import java.util.List;

/**
 * StudentService接口的实现类，提供学生相关的业务逻辑实现
 */
public class StudentServiceImpl implements StudentService {
    private StudentDAO studentDAO = new StudentDAOImpl();

    @Override
    public Student getStudentById(String studentId) throws SQLException {
        return studentDAO.getStudentById(studentId);
    }

    @Override
    public List<Student> getStudentsByName(String name) throws SQLException {
        return studentDAO.getStudentsByName(name);
    }

    @Override
    public List<Student> getStudentsByClassId(String classId) throws SQLException {
        return studentDAO.getStudentsByClassId(classId);
    }

    @Override
    public List<Student> getAllStudents() throws SQLException {
        return studentDAO.getAllStudents();
    }

    @Override
    public boolean addStudent(Student student) throws SQLException {
        // 检查学生ID是否已存在
        if (studentIdExists(student.getStudentId())) {
            return false;
        }
        return studentDAO.addStudent(student);
    }

    @Override
    public boolean updateStudent(Student student) throws SQLException {
        // 检查学生是否存在
        if (!studentIdExists(student.getStudentId())) {
            return false;
        }
        return studentDAO.updateStudent(student);
    }

    @Override
    public boolean deleteStudent(String studentId) throws SQLException {
        return studentDAO.deleteStudent(studentId);
    }

    @Override
    public boolean studentIdExists(String studentId) throws SQLException {
        return studentDAO.studentIdExists(studentId);
    }
}